using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using System.Reflection;

//对一些常用容器做Inspector包装，在使用前必须调用InitIfNot
//不应该在运行时修改内容
[Serializable]
public class InspectorDict<TKey, TVal> : Dictionary<TKey, TVal>
{
  [Serializable]
  private struct Pair
  {
    public TKey key;
    public TVal value;
  }

  [SerializeField]
  private List<Pair> _content;

  private Dictionary<TKey, TVal> _dictSelf => this;

  public void InitIfNot() {
    if (this.Count != 0 || _content == null || _content.Count == 0) {
      return;
    }

    foreach (var pair in _content) {
      if (!this.ContainsKey(pair.key)) {
        _dictSelf[pair.key] = pair.value;
      } else {
        Debug.LogError("[InspectorDict.Init] conflict:　" + pair.key.ToString());
      }
    }
  }

  public new TVal this[TKey key] {
    get => _dictSelf[key];
    set {
      Debug.LogError("[InspectorDict] SerializableDict should use as static data.");
    }
  }

  public new void Add(TKey key, TVal val) {
    Debug.LogError("[InspectorDict] SerializableDict should use as static data.");
  }

  public new bool TryAdd(TKey key, TVal val) {
    Debug.LogError("[InspectorDict] SerializableDict should use as static data.");
    return false;
  }

  public new void Remove(TKey key) {
    Debug.LogError("[InspectorDict] SerializableDict should use as static data.");
  }
}
